#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from oriolus.pith.packets.configreader import ConfigReader, ConfigReaderError
from unittest import TestCase, TestLoader, TextTestRunner, TestSuite

class TestConfigReader(TestCase):
    def setUp(self):
        self.__work_dir = os.path.abspath("./testdata/configs")
        self.__reader = ConfigReader()
        
    def test_trotter_config(self):
        path = os.path.join(self.__work_dir,"trotter_config.yaml")        
        options = self.__reader.read(path)
        
        self.assertEqual(3, len(options))
        self.assertEqual("bala-bala", options["workdir"])
        self.assertEqual("builtin", options["fetcher"])
        self.assertEqual(100, options["timeout"])
        
    def test_docker_config(self):
        path = os.path.join(self.__work_dir,"docker_config.yaml")        
        options = self.__reader.read(path)        

        self.assertEqual(3, len(options))
        self.assertEqual("all_users", options["repository_location"])
        self.assertEqual("docker_repository", options["repository_folder"])
        self.assertEqual("filesystem", options["repository_type"])
        
    def test_invalid_config(self):
        path = os.path.join(self.__work_dir,"invalid_config.yaml")        
        self.assertRaises(ConfigReaderError, self.__reader.read, path)
        
    def test_missing_config(self):
        path = os.path.join(self.__work_dir, "missing_config.yaml")
        self.assertRaises(ConfigReaderError, self.__reader.read, path)
        
if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestConfigReader)
    alltests = TestSuite(suite)
    TextTestRunner(verbosity=2).run(alltests)

